﻿using Bootstrap.Helper;
using Bootstrap.Template.Navbar;
using Bootstrap.Template.TemplateInnerItem;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Bootstrap.Control
{

    [ToolboxData("<{0}:BootstrapNavbar runat=server></{0}:BootstrapNavbar>")]
    public class BootstrapNavbar : WebControl
    {
        #region Properties

        [PersistenceMode(PersistenceMode.InnerProperty)]
        public List<AbstractBootstrapItem> InnerList { get; set; }

        #endregion

        #region Methods

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {

            BootstrapNavbarTemplateBegin templateBegin = new BootstrapNavbarTemplateBegin();
            
            writer.Write(templateBegin.TransformText());

            List<BootstrapNavbarTemplateItem> templateInnerList = new List<BootstrapNavbarTemplateItem>();

            foreach (var item in this.InnerList)
            {
                writer.Write(((IInnerItem)item).GetTemplate());
            }

            BootstrapNavbarTemplateEnd templateEnd = new BootstrapNavbarTemplateEnd();

            writer.Write(templateEnd.TransformText());
        }

        #endregion
    }
}
